package com.myself.common.define.model;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class CommonResult<T> {

    Integer code;

    String message;

    T data;

    public static CommonResult<Object> success() {
        return new CommonResult<>(200, "操作成功", null);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(200, "操作成功", data);
    }

    public static CommonResult<Object> fail() {
        return new CommonResult<>(500, "操作失败", null);
    }

    public static CommonResult<String> fail(String message) {
        if (StrUtil.isBlank(message)) {
            message = "操作失败";
        }
        return new CommonResult<>(500, message, null);
    }
}
